package chapter5.eg3;

import java.util.ArrayList;
import java.util.List;

public class ConsumerGroup {
  private List<ConsumerRunnable> consumers;

  public ConsumerGroup(int consumerNum, String groupId, String topic) {
    consumers = new ArrayList<>(consumerNum);
    for (int i = 0; i < consumerNum; i++) {
      ConsumerRunnable consumer = new ConsumerRunnable(groupId, topic);
      consumers.add(consumer);
    }
  }

  public void execute() {
    consumers.forEach(task -> new Thread(task).start());
  }
}
